<template>
    <div class="edu-page-warp">
        <condition-card
            @reset="reset"
            @search="onSubmit"
            label-width="110px"
            :advance="true"
            businessType="supervisorAssign"
            fieldsApi="/api/studentservice/advancedQuery/findFieldInfo"
            searchApi="/api/studentservice/advancedQuery/findResultList"
            searchApiMethod="post"
            @advanceQuery="advanceQuery"
        >
            <el-row :gutter="24" class="condition">
                <el-col :span="8">
                    <el-form-item :label="$t('label.grade')">
                        <el-date-picker
                            clearable
                            v-model="queryForm.grade"
                            value-format="yyyy"
                            type="year"
                            :placeholder="$t('common.text.all')"
                            style="width: 100%"
                            @change="currentDptId === '1' ? changeFaculty() : ''"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('label.college')">
                        <el-select
                            clearable
                            multiple
                            collapse-tags
                            v-model="queryForm.facultyList"
                            style="width: 100%;"
                            @change="changeFaculty"
                            filterable
                        >
                            <el-option
                                v-for="item in options.college"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('label.major')">
                        <el-select
                            v-model="queryForm.professionList"
                            style="width:100%"
                            multiple
                            collapse-tags
                            clearable
                        >
                            <el-option
                                v-for="item in options.major"
                                :key="item.value"
                                :label="item.label+'('+item.value+')'"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item :label="$t('label.trainingLevel')">
                        <el-select
                            v-model="queryForm.trainingLevelList"
                            style="width: 100%;"
                            multiple
                            collapse-tags
                            clearable
                        >
                            <el-option
                                v-for="item in options.trainingLevel"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('label.trainingCategory')">
                        <el-select
                            v-model="queryForm.trainingCategory"
                            clearable
                            style="width: 100%;"
                        >
                            <el-option
                                v-for="item in options.trainingCategory"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="在校状态">
                        <el-select v-model="queryForm.leaveSchool" style="width: 100%;" clearable>
                            <el-option
                                v-for="item in options.leaveSchool"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item label="是否指定">
                        <el-select v-model="queryForm.appointStatus" style="width: 100%;" clearable>
                            <el-option
                                v-for="item in options.appointStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('dic.degreeType')">
                        <el-select
                            v-model="queryForm.degreeType"
                            @change="currentDptId !== '1' ? changeFaculty() : ''"
                            style="width: 100%;"
                            clearable
                        >
                            <el-option
                                v-for="item in options.degreeType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item :label="$t('label.formLearning')">
                        <el-select v-model="queryForm.formLearning" style="width: 100%;" clearable>
                            <el-option
                                v-for="item in options.formLearning"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item label="入学开始时间">
                        <el-date-picker
                            clearable
                            v-model="queryForm.enrolDateStart"
                            type="datetime"
                            placeholder="入学开始时间"
                            style="width:100%"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="入学结束时间">
                        <el-date-picker
                            clearable
                            v-model="queryForm.enrolDateEnd"
                            type="datetime"
                            placeholder="入学结束时间"
                            style="width:100%"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="指定开始时间">
                        <el-date-picker
                            clearable
                            v-model="queryForm.appointTimeStart"
                            type="datetime"
                            placeholder="指定开始时间"
                            style="width:100%"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="8">
                    <el-form-item label="指定结束时间">
                        <el-date-picker
                            clearable
                            v-model="queryForm.appointTimeEnd"
                            type="datetime"
                            placeholder="指定结束时间"
                            style="width:100%"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
        </condition-card>
        <el-card shadow="never">
            <div class="edu-page-title">学生导师指定</div>
            <el-row>
                <el-col :span="4">
                    <el-input
                        v-model="queryForm.keyWord"
                        placeholder="请输入学生学号/姓名搜索"
                        @keyup.enter.native="onSubmit"
                        style="width:200px"
                    >
                        <i
                            class="el-icon-search"
                            slot="suffix"
                            style="margin-top:10px;cursor:pointer"
                            @click="onSubmit"
                        ></i>
                    </el-input>
                </el-col>
                <el-col :span="8">
                    <div class="empty-box" />
                </el-col>
                <el-col :span="12">
                    <div class="float-right">
                        <el-dropdown @command="handleCommand" v-if="visible.import">
                            <el-button type="primary">
                                {{$t("message.import")}}
                                <i
                                    class="el-icon-arrow-down el-icon--right"
                                ></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item command="download">下载模板</el-dropdown-item>
                                <el-dropdown-item command="import">{{$t("message.import")}}</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                        <el-button
                            type="primary"
                            @click="exportStu"
                            v-if="visible.export"
                        >{{$t("message.export")}}</el-button>
                        <el-button @click="openNameListDialog" v-if="visible.addNames">添加名单</el-button>
                    </div>
                </el-col>
            </el-row>
            <edu-table
                :data="students"
                size="mini"
                style="width:100%"
                :order="false"
                @page-change="handleCurrentChange"
                :total="queryForm.total_"
                :pageSize="queryForm.pageSize_"
                :pageNum="queryForm.pageNum_"
                @selection-change="exportSelectionChange"
            >
                <el-table-column
                    prop="studentId"
                    :label="$t('label.studentCode')"
                    fixed="left"
                    width="110px"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    :label="$t('label.studentName')"
                    fixed="left"
                    :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>
                <el-table-column :label="$t('label.grade')">
                    <template slot-scope="scope">{{ scope.row.grade }}</template>
                </el-table-column>
                <el-table-column :label="$t('label.college')" width="200" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                </el-table-column>
                <el-table-column :label="$t('label.major')" width="200" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                </el-table-column>
                <el-table-column :label="$t('label.trainingLevel')" width="100">
                    <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                </el-table-column>
                <el-table-column
                    :label="$t('label.trainingCategory')"
                    width="100"
                    prop="trainingCategoryI18n"
                ></el-table-column>
                <el-table-column label="导师" width="180" show-overflow-tooltip>
                    <template
                        slot-scope="scope"
                    >{{scope.row.teacherName?(scope.row.teacherName+'('+scope.row.teacherId+')'):null}}</template>
                </el-table-column>
                <el-table-column label="副导师" width="180" show-overflow-tooltip>
                    <template
                        slot-scope="scope"
                    >{{scope.row.viceTeacherName?(scope.row.viceTeacherName+'('+scope.row.viceTeacherId+')'):null}}</template>
                </el-table-column>
                <el-table-column :label="$t('dic.degreeType')" width="100" prop="degreeTypeI18n"></el-table-column>
                <el-table-column
                    :label="$t('label.formLearning')"
                    width="100"
                    prop="formLearningI18n"
                ></el-table-column>
                <el-table-column
                    :label="$t('label.leaveSchool')"
                    width="100"
                    prop="leaveSchoolI18n"
                ></el-table-column>
                <el-table-column label="入学时间" width="160">
                    <template slot-scope="scope">{{getDateFormat(scope.row.enrolDate,"YYYY-MM-DD")}}</template>
                </el-table-column>
                <el-table-column label="指定时间" width="160">
                    <template slot-scope="scope">{{getDateFormat(scope.row.appointTime)}}</template>
                </el-table-column>
                <el-table-column
                    :label="$t('label.operation')"
                    fixed="right"
                    v-if="visible.selectTeacher||visible.remove"
                    :width="width"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            v-if="visible.selectTeacher&&!scope.row.teacherId"
                            @click="operate(scope,1)"
                        >指定导师</el-button>
                        <el-button
                            type="text"
                            v-if="visible.unregistTeacher&&scope.row.teacherId"
                            @click="cancelTeacher(scope,true)"
                        >撤销导师</el-button>

                        <el-button
                            type="text"
                            v-if="visible.selectTeacher&&!scope.row.viceTeacherId"
                            @click="operate(scope,2)"
                        >指定副导师</el-button>
                        <el-button
                            type="text"
                            v-if="visible.unregistTeacher&&scope.row.viceTeacherId"
                            @click="cancelTeacher(scope,false)"
                        >撤销副导师</el-button>
                        <el-button
                            type="text"
                            @click="deleteStu(scope)"
                            v-if="visible.remove&&!scope.row.teacherId&&!scope.row.viceTeacherId"
                        >移除</el-button>
                    </template>
                </el-table-column>
            </edu-table>
            <edu-dialog
                title="添加名单"
                width="70%"
                ref="nameListDialog"
                :auto-height="true"
                @close="clearNameList"
            >
                <el-form label-width="80px" label-suffix=":">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item :label="$t('label.grade')">
                                <el-date-picker
                                    clearable
                                    v-model="nameListForm.grade"
                                    value-format="yyyy"
                                    type="year"
                                    :placeholder="$t('common.text.all')"
                                    style="width: 100%"
                                    @change="currentDptId === '1' ? changeFaculty2() : ''"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item :label="$t('label.college')">
                                <el-select
                                    clearable
                                    multiple
                                    collapse-tags
                                    v-model="nameListForm.facultyList"
                                    style="width: 100%"
                                    @change="changeFaculty2"
                                    filterable
                                >
                                    <el-option
                                        v-for="item in options.college"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item :label="$t('label.major')">
                                <el-select
                                    clearable
                                    v-model="nameListForm.professionList"
                                    style="width: 100%"
                                    multiple
                                    collapse-tags
                                    filterable
                                >
                                    <el-option
                                        v-for="item in options.major2"
                                        :key="item.value"
                                        :label="item.label+'('+item.value+')'"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item :label="$t('label.trainingLevel')">
                                <el-select
                                    clearable
                                    v-model="nameListForm.trainingLevelList"
                                    style="width: 100%"
                                    multiple
                                    collapse-tags
                                >
                                    <el-option
                                        v-for="item in options.trainingLevel"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item :label="$t('label.trainingCategory')">
                                <el-select
                                    clearable
                                    v-model="nameListForm.trainingCategory"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in options.trainingCategory"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <div class="float-right">
                                <el-button @click="resetNameList">{{$t("message.reset")}}</el-button>
                                <el-button
                                    type="primary"
                                    @click="onNameListSubmit"
                                >{{$t("message.filter")}}</el-button>
                                <!-- <el-button type="primary">高级查询</el-button> -->
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
                <hr />
                <div style="margin-bottom:20px">
                    <el-input
                        v-model="nameListForm.keyWord"
                        placeholder="请输入学生学号/姓名搜索"
                        @keyup.enter.native="onNameListSubmit"
                        style="width:200px"
                    >
                        <i
                            class="el-icon-search"
                            slot="suffix"
                            style="margin-top:10px;cursor:pointer"
                            @click="onNameListSubmit"
                        ></i>
                    </el-input>
                </div>
                <edu-table
                    :data="studentNameList"
                    size="mini"
                    style="width:100%"
                    @page-change="nameListFormChangePage"
                    :total="nameListForm.total_"
                    :pageSize="nameListForm.pageSize_"
                    :pageNum="nameListForm.pageNum_"
                    @selection-change="selectionChange"
                    :order="false"
                >
                    <el-table-column prop="studentId" :label="$t('label.studentCode')" width="100" />
                    <el-table-column
                        :label="$t('label.studentName')"
                        width="100"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">{{ scope.row.name }}</template>
                    </el-table-column>
                    <el-table-column
                        :label="$t('label.grade')"
                        width="80"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">{{ scope.row.grade }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.college')" :show-overflow-tooltip="true">
                        <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.major')" :show-overflow-tooltip="true">
                        <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                    </el-table-column>
                    <el-table-column
                        :label="$t('label.trainingLevel')"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                    </el-table-column>
                    <el-table-column
                        :label="$t('label.trainingCategory')"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">{{ scope.row.trainingCategoryI18n }}</template>
                    </el-table-column>
                </edu-table>
                <template slot="buttons">
                    <el-button @click="closeDialog">{{$t('message.return')}}</el-button>
                    <el-button type="primary" @click="saveNameList">{{$t('message.confirm')}}</el-button>
                </template>
            </edu-dialog>

            <edu-dialog
                title="指定导师"
                width="70%"
                :autoHeight="true"
                ref="teacherDialog"
                @close="clearTeachers"
                @confirm="saveTeachers"
                :showButtons="false"
            >
                <el-form label-width="80px" label-suffix=":">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                                <el-select
                                    v-model="teacherForm.facultyList"
                                    style="width: 100%"
                                    multiple
                                    clearable
                                    filterable
                                    collapse-tags
                                    :disabled = 'isFlag'
                                >
                                    <el-option
                                        v-for="item in options.college"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="职称">
                                <el-select
                                    v-model="teacherForm.title"
                                    style="width: 100%"
                                    clearable
                                    filterable
                                    :disabled = 'isFlag'
                                >
                                    <el-option
                                        v-for="item in options.title"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <div class="float-right">
                                <el-button @click="resetTeacherForm">{{$t('message.reset')}}</el-button>
                                <el-button
                                    type="primary"
                                    @click="onTeacherFormSubmit"
                                >{{$t('message.filter')}}</el-button>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
                <hr />
                <div style="margin-bottom:20px">
                    <el-input
                        v-model="teacherForm.keyWord"
                        placeholder="请输入导师工号/姓名搜索"
                        @keyup.enter.native="onTeacherFormSubmit"
                        style="width:200px"
                    >
                        <i
                            class="el-icon-search"
                            slot="suffix"
                            style="margin-top:10px;cursor:pointer"
                            @click="onTeacherFormSubmit"
                        ></i>
                    </el-input>
                </div>
                <edu-table
                    :data="teachers"
                    size="mini"
                    style="width:100%"
                    :selection="false"
                    :order="false"
                    @page-change="teacherFormChangePage"
                    :total="teacherForm.total_"
                    :pageSize="teacherForm.pageSize_"
                    :pageNum="teacherForm.pageNum_"
                >
                    <el-table-column label="工号" prop="code" width="100" />
                    <el-table-column
                        :label="$t('label.teachName')"
                        width="100"
                        show-overflow-tooltip
                    >
                        <template slot-scope="scope">{{ scope.row.name }}</template>
                    </el-table-column>
                    <el-table-column label="职称" width="200" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.titleI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.college')" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                    </el-table-column>
                    <el-table-column label="硕士人数" width="100">
                        <template slot-scope="scope">{{ scope.row.masterDegree }}</template>
                    </el-table-column>
                    <el-table-column label="博士人数" width="100">
                        <template slot-scope="scope">{{ scope.row.doctorNum }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.operation')" width="70">
                        <template slot-scope="scope">
                            <el-button @click="assignTeacher(scope)" type="text">指定</el-button>
                        </template>
                    </el-table-column>
                </edu-table>
            </edu-dialog>
        </el-card>
        <edu-dialog
            title="导入学生信息"
            width="50%"
            ref="uploadDialog"
            @close="clearFiles"
            @confirm="uploadFile"
        >
            <div style="height:100px">
                <el-form label-width="85px">
                    <el-form-item>
                        <el-upload
                            ref="upload"
                            :on-success="uploadDone"
                            :on-error="onError"
                            :auto-upload="false"
                            :multiple="false"
                            :on-change="(file, fileList)=>{this.fileList = fileList}"
                            :limit="1"
                            accept=".xlsx"
                            action="api/studentservice/stuAppoint/importStuAppointTea"
                            :before-upload="beforeAvatarUpload"
                        >
                            <el-button
                                slot="trigger"
                                size="small"
                                type="primary"
                            >{{$t('label.selectFile')}}</el-button>
                            <div slot="tip" class="el-upload__tip">只能上传.xlsx文件</div>
                        </el-upload>
                    </el-form-item>
                </el-form>
            </div>
        </edu-dialog>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import {
    getAppointList,
    getNoAppointStuList,
    selectedStu,
    getAppointTeaList,
    downloadStuTemplate,
    exportAppointListExcel,
    deleteStuAppointed,
    appointTea,
    deleteAppointTea
} from "common/src/api/studentinfo";
import UTILS from "common/src/utils/utils";
import moment from "moment";
import fetch from "common/src/utils;
export default {
    name: "supervisorAssign",
    data() {
        return {
            isFlag:false,
            queryForm: {
                grade: "",
                facultyList: [],
                professionList: [],
                trainingLevelList: [],
                trainingCategory: "",
                degreeType: "",
                formLearning: "",
                leaveSchool: "",
                appointStatus: "",
                enrolDateStart: "",
                enrolDateEnd: "",
                appointTimeStart: "",
                appointTimeEnd: "",
                keyWord: "",
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            nameListForm: {
                grade: "",
                facultyList: [],
                professionList: [],
                trainingLevelList: [],
                trainingCategory: "",
                keyWord: "",
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            teacherForm: {
                title: "",
                facultyList: [],
                keyWord: "",
                pageSize_: 20,
                pageNum_: 1,
                total_: 0,
                appointType: null,
                studentId: null
            },
            options: {
                college: [],
                trainingLevel: [],
                formLearning: [],
                trainingCategory: [],
                degreeType: [],
                major: [],
                major2: [],
                title: [],
                leaveSchool: [],
                appointStatus: []
            },
            students: [],
            studentNameList: [],
            selectedNameList: [],
            teachers: [],
            fileList: [],
            visible: {
                read: false,
                export: false,
                import: false,
                addNames: false,
                selectTeacher: false,
                unregistTeacher: false,
                remove: false
            },
            width: 0,
            currentDptId: null,
            exportStudents: null,
            studentIdList: null
        };
    },
    mounted() {
        this.init();
        let session = localStorage.getItem("sessiondata");
        session = JSON.parse(session);
        let user = session.mockUser || session.user;
        this.currentDptId = user.currentManageDptId;
        if (user.uid == "admin1") {
            this.visible.read = true;
            this.visible.export = true;
        }

        //1.管理员 2.教务员 3.导师 4.老师 5.留办老师 6.学生
        if (user.innerRoles.includes("1")) {
            this.visible.read = true;
            this.visible.export = true;
            this.visible.import = true;
            this.visible.addNames = true;
            this.visible.remove = true;
            this.visible.selectTeacher = true;
            this.visible.unregistTeacher = true;
            this.width = 210;
        }
        if (user.innerRoles.includes("2")) {
            this.visible.read = true;
            this.visible.export = true;
            this.visible.selectTeacher = true;
            this.visible.unregistTeacher = true;
            this.width = 210;
        }
    },
    methods: {
        init() {
            let yes = {
                    label: this.$t("message.yes"),
                    value: 1
                },
                no = {
                    label: this.$t("message.no"),
                    value: 0
                };
            this.options.appointStatus.push(yes);
            this.options.appointStatus.push(no);

            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: [
                    "X_YX",
                    "X_PYCC",
                    "X_PYLB",
                    "X_XWLX",
                    "X_XXXS",
                    "profession",
                    "X_LXZT"
                ]
            };
            queryDic(data).then(res => {
                if (res.code == 200) {
                    UTILS.fillSelect(
                        {
                            college: "X_YX",
                            trainingLevel: "X_PYCC",
                            formLearning: "X_XXXS",
                            trainingCategory: "X_PYLB",
                            degreeType: "X_XWLX",
                            title: "profession",
                            leaveSchool: "X_LXZT"
                        },
                        res.data,
                        this.options
                    );
                }
            });
            this.onSubmit();
        },
        changeFaculty() {
            this.options.major = [];
            this.queryForm.professionList = [];
            if (
                this.currentDptId == "1" &&
                this.queryForm.facultyList.length == 0
            ) {
                return;
            }
            if (
                this.currentDptId != "1" &&
                this.queryForm.facultyList.length == 0 &&
                !this.queryForm.degreeType
            ) {
                return;
            }
            this.bindMajor(
                { major: "G_ZY" },
                this.queryForm.facultyList,
                this.queryForm.grade,
                this.queryForm.degreeType ? [this.queryForm.degreeType] : []
            );
        },
        changeFaculty2() {
            this.options.major2 = [];
            this.nameListForm.professionList = [];
            if (this.nameListForm.facultyList.length == 0) {
                return;
            }
            this.bindMajor(
                { major2: "G_ZY" },
                this.nameListForm.facultyList,
                this.nameListForm.grade
            );
        },
        bindMajor(jsonObj, facultys = [], grade = null, degreeType = []) {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: facultys,
                    specilaCode: "XY2ZY",
                    grade: grade,
                    degreeType: degreeType,
                    facultys: facultys
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200)
                    UTILS.fillSelect(jsonObj, res.data, this.options);
            });
        },
        onSubmit(isActiveTrigger = true, isFirstPage = true) {
            if (
                this.queryForm.enrolDateStart &&
                this.queryForm.enrolDateEnd &&
                this.queryForm.enrolDateStart > this.queryForm.enrolDateEnd
            ) {
                this.$message({
                    type: "warning",
                    message: "入学开始时间不能大于入学结束时间"
                });
                return;
            }
            if (
                this.queryForm.appointTimeStart &&
                this.queryForm.appointTimeEnd &&
                this.queryForm.appointTimeStart > this.queryForm.appointTimeEnd
            ) {
                this.$message({
                    type: "warning",
                    message: "指定开始时间不能大于指定结束时间"
                });
                return;
            }
            if (isFirstPage) {
                this.queryForm.pageNum_ = 1;
            }
            if (isActiveTrigger && this.studentIdList != null) {
                this.studentIdList = null;
            }
            let param = null;
            if (this.studentIdList) {
                param = {
                    studentIdList: this.studentIdList,
                    pageNum_: this.queryForm.pageNum_,
                    pageSize_: this.queryForm.pageSize_,
                    advanceType: 1
                };
            } else {
                param = this.getQueryParam();
            }
            getAppointList(param).then(res => {
                if (res.code == 200) {
                    this.students = res.data.list;
                    this.queryForm.total_ = res.data.total_;
                }
            });
        },
        getQueryParam() {
            let postData = _.cloneDeep(this.queryForm);
            return postData;
        },
        reset() {
            this.queryForm.grade = "";
            this.queryForm.facultyList = [];
            this.queryForm.trainingLevelList = [];
            this.queryForm.professionList = [];
            this.queryForm.trainingCategory = "";
            this.queryForm.degreeType = "";
            this.queryForm.formLearning = "";
            this.queryForm.leaveSchool = "";
            this.queryForm.appointStatus = "";
            this.queryForm.enrolDateStart = "";
            this.queryForm.enrolDateEnd = "";
            this.queryForm.appointTimeStart = "";
            this.queryForm.appointTimeEnd = "";
            this.queryForm.keyWord = "";
            this.options.major = [];
            this.queryForm.pageNum_ = 1;
            // this.advanceQuery(this.queryForm);
            getAppointList(this.queryForm).then(response => {
                if (response.code === 200) {
                    this.students = response.data.list;
                    this.queryForm.total_ = response.data.total_;
                }
            });
        },
        operate(scope, appointType) {
            this.teacherForm.appointType = appointType;
            this.teacherForm.studentId = scope.row.studentId;
            this.$refs.teacherDialog.open();
            //打开对话框遮蔽层与请求遮蔽层冲突，延迟请求
            setTimeout(() => {
                this.onTeacherFormSubmit();
            }, 200);
        },
        deleteStu(scope) {
            this.$confirm("是否确定将学生移除", this.$t("message.prompt"), {
                confirmButtonText: this.$t("message.confirm"),
                cancelButtonText: this.$t("message.cancel"),
                type: "warning"
            }).then(() => {
                deleteStuAppointed(scope.row.id).then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: "success",
                            message: "移除成功"
                        });
                        this.onSubmit(false, false);
                    }
                });
            });
        },
        //打开名单对话框
        openNameListDialog() {
            this.$refs.nameListDialog.open();
            this.nameListForm.total_ = 0;
            this.nameListForm.pageSize_ = 20;
            this.nameListForm.pageNum_ = 1;
            //打开对话框遮蔽层与请求遮蔽层冲突，延迟请求
            setTimeout(() => {
                this.onNameListSubmit();
            }, 200);
        },
        //重置名单
        resetNameList() {
            this.nameListForm.grade = "";
            this.nameListForm.facultyList = [];
            this.nameListForm.trainingLevelList = [];
            this.nameListForm.professionList = [];
            this.nameListForm.trainingCategory = "";
            this.nameListForm.keyWord = "";
            setTimeout(() => {
                this.onNameListSubmit();
            }, 200);
        },
        //查询名单
        onNameListSubmit(isFirstPage = true) {
            if (isFirstPage) {
                this.nameListForm.pageNum_ = 1;
            }
            getNoAppointStuList(this.nameListForm).then(res => {
                if (res.code == 200) {
                    this.studentNameList = res.data.list;
                    this.nameListForm.total_ = res.data.total_;
                }
            });
        },
        //关闭名单对话框
        clearNameList() {
            this.studentNameList = [];
            this.options.major2 = [];
            this.resetNameList();
        },
        selectionChange(val) {
            this.selectedNameList = val;
        },
        //保存名单
        saveNameList() {
            if (this.selectedNameList.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请选中学生"
                });
                return;
            }
            let saveData = this.selectedNameList.map(n => {
                return {
                    studentId: n.studentId
                };
            });
            selectedStu({ stuAppointTeachs: saveData }).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: "success",
                        message: this.$t("message.saveSuccess")
                    });
                    this.$refs.nameListDialog.close();
                    this.onSubmit(true, true);
                }
            });
        },
        //关闭指定导师对话框
        clearTeachers() {
            this.teachers = [];
            this.teacherForm.appointType = null;
            this.teacherForm.studentId = null;
            this.teacherForm.title = "";
            this.teacherForm.facultyList = [];
            this.teacherForm.keyWord = "";
            // this.resetTeacherForm();
        },
        //保存指定导师
        saveTeachers() {
            this.$refs.teacherDialog.close();
        },
        //重置导师表单
        resetTeacherForm() {
            this.teacherForm.title = "";
            this.teacherForm.facultyList = [];
            this.teacherForm.keyWord = "";
            this.teacherForm.pageNum_ = 1;
            getAppointTeaList(this.teacherForm).then(res => {
                if (res.code == 200) {
                    this.teachers = res.data.list;
                    this.teacherForm.total_ = res.data.total_;
                }
            });
        },
        //查询导师
        onTeacherFormSubmit(isFirstPage = true) {
            if (isFirstPage) {
                this.teacherForm.pageNum_ = 1;
            }
            getAppointTeaList(this.teacherForm).then(res => {
                if (res.code == 200) {
                    this.teachers = res.data.list;
                    this.teacherForm.total_ = res.data.total_;
                }
            });
        },
        //指定导师
        assignTeacher(scope) {
            let data = {
                studentId: this.teacherForm.studentId
            };
            if (this.teacherForm.appointType == 1) {
                data.teacherId = scope.row.code;
            } else {
                data.viceTeacherId = scope.row.code;
            }
            appointTea(data).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: "success",
                        message: "指定导师成功"
                    });
                    this.$refs.teacherDialog.close();
                    this.onSubmit(false, false);
                }
            });
        },
        cancelTeacher(scope, flag) {
            let msg = ''
            let successMsg = ''
            if(flag) {
                msg = "是否确定撤销导师指定？"
            } else {
                msg = "是否确定撤销副导师指定？"
            }
            this.$confirm(msg, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    let data = {
                        studentId: scope.row.studentId
                    };
                    if (flag) {
                        data.teacherId = null;
                        data.viceTeacherId = scope.row.viceTeacherId;
                        successMsg = '撤销导师成功'
                    } else {
                        data.teacherId = scope.row.teacherId;
                        data.viceTeacherId = null;
                        successMsg = '撤销副导师成功'
                    }
                    deleteAppointTea(data).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: "success",
                                message: successMsg
                            });
                            this.onSubmit(false, false);
                        }
                    });
                })
                .catch(() => {});
        },
        handleCurrentChange(val) {
            this.queryForm.pageSize_ = val.pageSize;
            this.queryForm.pageNum_ = val.pageNum;
            this.onSubmit(false, false);
        },
        nameListFormChangePage(val) {
            this.nameListForm.pageSize_ = val.pageSize;
            this.nameListForm.pageNum_ = val.pageNum;
            this.onNameListSubmit(false);
        },
        //导入和下载模板
        handleCommand(command) {
            if (command == "download") {
                window.open(downloadStuTemplate());
            } else {
                this.$refs.uploadDialog.open();
            }
        },
        //导出学生名单
        exportStu() {
            let query = null;
            if (this.exportStudents && this.exportStudents.length > 0) {
                query = {
                    ids: this.exportStudents.map(s => s.id).join(",")
                };
            } else {
                query = this.getQueryParam();
                if (query.facultyList.length > 0) {
                    query.facultys = query.facultyList.join(",");
                }
                if (query.professionList.length > 0) {
                    query.professions = query.professionList.join(",");
                }
                if (query.trainingLevelList.length > 0) {
                    query.trainingLevels = query.trainingLevelList.join(",");
                }
                query.facultyList = null;
                query.professionList = null;
                query.trainingLevelList = null;
                query.pageSize_ = null;
                query.pageNum_ = null;
                query.total_ = null;
            }
            let loading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(255, 255, 255, .48)"
            });
            exportAppointListExcel(query).then(res => {
                if (res.code == 200) {
                    this.delayRequest(res.data.key, loading);
                } else {
                    loading.close();
                }
            });
        },
        async delayRequest(key, loading) {
            await new Promise(resolve => setTimeout(resolve, 5000));
            fetch({
                url: "/api/studentservice/stuAppoint/result/" + key,
                showMask: false
            })
                .then(res => {
                    if (res.code == 200 && res.data.status) {
                        loading.close();
                        let path =
                            "/api/studentservice/stuAppoint/exportAppointList?path=" +
                            res.data.path;
                        window.open(path);
                    } else {
                        this.delayRequest(key, loading);
                    }
                })
                .catch(err => {
                    loading.close();
                    throw err;
                });
        },
        teacherFormChangePage(val) {
            this.teacherForm.pageSize_ = val.pageSize;
            this.teacherForm.pageNum_ = val.pageNum;
            this.onTeacherFormSubmit(false);
        },
        uploadDone(res, file, fileList) {
            if (res.code == 200) {
                this.$message({
                    type: "success",
                    message: this.$t("common.tips.uploadSuccess")
                });
                this.$refs.uploadDialog.close();
            } else {
                this.$message({
                    type: "error",
                    message: res.msg
                        ? res.msg
                        : this.$t("common.tips.dataFormatError")
                });
                this.clearFiles();
            }
        },
        onError(err, file, fileList) {
            let msg = JSON.parse(err.message);
            this.$message({
                type: "error",
                message: msg.message
            });
        },
        beforeAvatarUpload(file) {
            if (!file.name.match(/\.xlsx$/)) {
                this.$message.error("上传文件必须是.xlsx");
                this.clearFiles();
                return false;
            }
            const isLt2M = file.size / 1024 / 1024 < 10;
            if (!isLt2M) {
                this.$message.error("上传文件大小不能超过 10MB!");
                this.clearFiles();
                return false;
            }
        },
        clearFiles() {
            this.$refs.upload.clearFiles();
            this.fileList = [];
        },
        uploadFile() {
            if (this.fileList.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请选择要上传的文件"
                });
                return;
            }
            this.$refs.upload.submit();
        },
        getDateFormat(val, format = "YYYY-MM-DD HH:mm:ss") {
            return val ? moment(val).format(format) : null;
        },
        closeDialog() {
            this.$refs.nameListDialog.close();
        },
        exportSelectionChange(val) {
            this.exportStudents = val;
        },
        //高级查询
        advanceQuery(data) {
            this.studentIdList = data;
            this.queryForm.pageNum_ = 1;
            let param = {
                studentIdList: data,
                pageNum_: this.queryForm.pageNum_,
                pageSize_: this.queryForm.pageSize_,
                advanceType: 1
            };
            getAppointList(param).then(response => {
                if (response.code === 200) {
                    this.students = response.data.list;
                    this.queryForm.total_ = response.data.total_;
                }
            });
        }
    },
    watch:{
        'teacherForm.keyWord':{
            handler: function(navl,oval){
                if(navl !== ''){
                    this.teacherForm.title = "";
                    this.teacherForm.facultyList = [];
                    this.isFlag = true
                }else{
                    this.isFlag = false
                }
            },
            deep:true
        }
    }
};
</script>
<style lang="scss" scoped>
.condition {
    ::v-deep .el-select__tags {
        span span:only-child {
            text-overflow: ellipsis;
            overflow: hidden;
            width: 200px;
        }
        span span:nth-last-child(2) {
            text-overflow: ellipsis;
            overflow: hidden;
            width: 110px;
        }
        input {
            display: none;
        }
    }
}
</style>